$(document).ready(function() {
//Fullcalendar		
	var date = new Date();
	var d = date.getDate();
	var m = date.getMonth();
	var y = date.getFullYear();
    $('#calendar').fullCalendar({
    		firstDay:'1',
    		weekMode:'liquid',
    		aspectRatio: '1.5',
			theme:true,
			selectable:true,
			editable:true,
			draggable:true,
			droppable:true,
			timeFormat:'H:mm',
	    	axisFormat:'H:mm',
	    	monthNames:["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"],
            monthNamesShort:["Jan","Fev","Mar","Avr","Mai","Juin","Juil","Aou","Sep","Oct","Nov","Dec"],
            dayNames:["Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi"],
            dayNamesShort:["Dim","Lun","Mar","Mer","Jeu","Ven","Sam"],
            buttonText:{
                prev:"&nbsp;&#9668;&nbsp;",
                next:"&nbsp;&#9658;&nbsp;",
                prevYear:"&nbsp;&lt;&lt;&nbsp;",
                nextYear:"&nbsp;&gt;&gt;&nbsp;",
                today:"Auj.",
                month:"mois",
                week:"semaine",
                day:"jour"
            },
	    	columnFormat:{
			    month: 'ddd',    // Mon
			    week: 'dddd d', // Mon 9/7
			    day: 'dddd d MMMM'  // Monday 9/7
			},
			titleFormat:{
			    month: 'MMMM yyyy',                             // February 2012
			    week: "d MMMM [ yyyy]{ 'au' d MMMM yyyy}", // Feb 13 - 14 2012
			    day: 'dddd d MMMM yyyy'                  // Tuesday, Feb 14, 2009
			},
	    	allDayText:'Journée entière',
			header:{
			    left:   'prev title next, today',
			    center: '',
			    right:  'agendaWeek,agendaDay,month'
				},
			
			eventSources: [

			        // your event source
			        {
			            events: [ // put the array in the `events` property
			                {
                                title: 'Réunion commerciale',
                                start: new Date(y, m, 1),
                                color: '#5c90b5'
                            },
                            {
                                title: 'Séminaire',
                                start: new Date(y, m, 5),
                                end: new Date(y, m, 8),
                                color: '#5c90f5'
                            },
                            {
                                id: 999,
                                title: 'Réunion hebdomadaire',
                                start: new Date(y, m, 2, 16, 0),
                                end: new Date(y, m, 3, 18, 0),
                                allDay: false,
                                color: '#5c90b5'
                            },
                            {
                                id: 999,
                                title: 'Réunion hebdomadaire',
                                start: new Date(y, m, 9, 16, 0),
                                end: new Date(y, m, 10, 18, 0),
                                allDay: false,
                                color: '#5c90f5'
                            },
                            {
                                title: 'RDV 1',
                                start: new Date(y, m, 30, 10, 30),
                                end: new Date(y, m, d+1, 14, 0),
                                allDay: false,
                                color: '#5c90b5'
                            },
                            {
                                title: 'RDV 2',
                                start: new Date(y, m, 14, 12, 0),
                                end: new Date(y, m, 15, 14, 0),
                                allDay: false,
                                color: '#5c90f5'
                            },
                            {
                                title: 'RDV 3',
                                start: new Date(y, m, 18),
                                end: new Date(y, m, 20),
                                allDay: false,
                                color: '#5c90b5'
                            },
                            {
                                title: 'RDV 4',
                                start: new Date(y, m, 27),
                                end: new Date(y, m, 29),
                                url: 'http://www.ajf-finance.fr',
                                color: '#5c90f5'
                            }
			            ]
			        },
					{
						url: 'https://www.google.com/calendar/feeds/ddk3tivrtfhv9jubvh020af23s%40group.calendar.google.com/public/basic',
						className: 'calendar_blue'
					}
			
			
			    ],
			
			drop: function(date, allDay) { // this function is called when something is dropped
		
			// retrieve the dropped element's stored Event Object
			var originalEventObject = $(this).data('eventObject');
			
			// we need to copy it, so that multiple events don't have a reference to the same object
			var copiedEventObject = $.extend({}, originalEventObject);
			
			// assign it the date that was reported
			copiedEventObject.start = date;
			copiedEventObject.allDay = allDay;
			
			// render the event on the calendar
			// the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
			$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
			
			// is the "remove after drop" checkbox checked?
			if ($('#drop-remove').is(':checked')) {
				// if so, remove the element from the "Draggable Events" list
				$(this).remove();
			}
			
		}
	        
	    });
	
	$('ul#calendar_drag_list li a').each(function() {
	
		// create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
		// it doesn't need to have a start or end
		var eventObject = {
			title: $.trim($(this).text()), // use the element's text as the event title
			className: 'calendar_blue'
		};
		
		// store the Event Object in the DOM element so we can get to it later
		$(this).data('eventObject', eventObject);
		
		// make the event draggable using jQuery UI
		$(this).draggable({
			zIndex: 999,
			revert: true,      // will cause the event to go back to its
			revertDuration: 10,  //  original position after the drag
			cursorAt: { top:15, left: 0 }
		});
		
	});
});